﻿using Autofac.Extras.DynamicProxy;
using Publicuse.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Interface
{
    /// <summary>
    /// ADO.NET基类操作接口
    /// </summary>
    [Intercept(typeof(IAutofacAop))]
    public interface IBaseService
    {
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="user"></param>
        /// <param name="msg"></param>
        int AddInfo<T>(T t, out string msg) where T : class, new();
        List<int> AddInfo<T>(List<T> t, out string msg) where T : class, new();

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="user"></param>
        /// <param name="msg"></param>
        int UpdateInfo<T>(T t, out string msg) where T : class, new();
        List<int> UpdateInfo<T>(List<T> t, out string msg) where T : class, new();

        /// <summary>
        /// 就是通过json字符串找出更新的字段
        /// </summary>
        /// <param name="type"></param>
        /// <param name="json"></param>
        /// <returns></returns>
        public int Update<T>(string json, int id, out string msg) where T : class, new();

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t"></param>
        /// <param name="msg"></param>
        int DeleteInfo<T>(T t, out string msg) where T : class, new();

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sqlParameters"></param>
        /// <param name="msg"></param>
        /// <param name="list"></param>
        void GetInfoList<T>(string sql, object[] sqlParameters, bool isproc, out string msg, out List<T> list) where T : class, new();

        /// <summary>
        /// 分页查询列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="storedprocedure"></param>
        /// <param name="tablename"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sqlWhere"></param>
        /// <param name="sortFile"></param>
        /// <param name="srotType"></param>
        /// <param name="count"></param>
        /// <param name="exception"></param>
        /// <param name="list"></param>
        void GetInfoList<T>(string storedprocedure, string tablename, string queryFile, int pageIndex, int pageSize, string sqlWhere,
            string sortFile, string srotType, out long count, out string exception, out List<T> list) where T : class, new();

        /// <summary>
        /// 分页查询列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="msg"></param>
        /// <param name="list"></param>
        /// <param name="totalCount"></param>
        void GetList<T>(CommonQuery query, out string msg, out List<T> list, out long totalCount) where T : class, new();

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="query"></param>
        /// <param name="msg"></param>
        /// <param name="list"></param>
        void GetList<T>(CommonQuery query, out string msg, out List<T> list) where T : class, new();

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sqlParameters"></param>
        /// <param name="msg"></param>
        /// <param name="list"></param>
        void QueryInfoByID<T>(long id, object[] sqlParameters, out string msg, out T t) where T : class, new();

        /// <summary>
        /// 查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        void QueryInfoByID<T>(long id, out string msg, out T data) where T : class, new();

        /// <summary>
        /// 获取数据集
        /// </summary>
        /// <param name="sqlstr"></param>
        /// <param name="param"></param>
        /// <param name="isproc"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        DataSet GetDataSet(string sqlstr, object param, bool isproc, out string exception);

        bool GetDataSet(string sql, out string exception, out DataSet dataSet);

        /// <summary>
        /// 获取数据表
        /// </summary>
        /// <param name="sqlstr"></param>
        /// <param name="tuples"></param>
        /// <param name="exception"></param>
        /// <returns></returns>
        DataTable GetDataTable(string sqlstr, List<Tuple<string, string, ExcuteType>> tuples, out string exception);

        /// <summary>
        /// 获取数据集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="tuples"></param>
        /// <param name="exception"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        bool GetList<T>(string sql, List<Tuple<string, string, ExcuteType>> tuples, out string exception, out List<T> list) where T : new();

        /// <summary>
        /// 根据条件获取数据集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="tuples"></param>
        /// <param name="msg"></param>
        /// <param name="t"></param>
        void QueryInfoBySql<T>(string sql, List<Tuple<string, string, ExcuteType>> tuples, out string msg, out T t) where T : class, new();

        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pairs"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        bool ExecuteSql(string sql, Dictionary<string, string> pairs, out string msg, ExcuteType type = ExcuteType.Equal);

        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="tuples"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        bool ExecuteSql(string sql, List<Tuple<string, string, ExcuteType>> tuples, out string msg);

        /// <summary>
        /// 执行批量SQL
        /// </summary>
        /// <param name="pairs"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        bool ExecuteSqls(List<Tuple<string, Dictionary<string, string>>> pairs, out string msg);

    }
}
